using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using Microsoft.Data.Sqlite;
using System.IO;
using System.Net;
using System.Threading;
using System.Diagnostics;
using System.Diagnostics.PerformanceData;
//using System.Configuration;//调用配置文件

namespace 信息记录系统
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.dgv1.AutoGenerateColumns = false;
            this.dgv2.AutoGenerateColumns = false;
            this.dataGridView3.AutoGenerateColumns = false;
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //dataGridView1.AllowUserToAddRows = false;//不显示最后一行
            this.dgv1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//选中整行
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form4 f1 = new Form4();
            f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
            f1.ShowDialog();//禁止操作
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("功能暂未开放！");
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //this.toolStripStatusLabel3.Text = "系统当前时间：" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            //this.timer1.Interval = 1000;
            //this.timer1.Start();
            string constr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;//实例化数据库获取数据库
            MySqlConnection conn = null;
            try
            {
                conn = new MySqlConnection(constr);
                conn.Open();
                if (conn.State == ConnectionState.Open)
                {
                    //MessageBox.Show("数据库连接成功！");
                    //加载的时候弹出搜索框
                    /*search searchopen = new search();
                    searchopen.StartPosition = FormStartPosition.CenterScreen;//居中显示
                    searchopen.ShowDialog();*/
                }
                if (conn.State == ConnectionState.Closed)
                {
                    MessageBox.Show("数据库已关闭！");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
            finally
            {
                conn.Close();
            }
        }

        private void toolStripStatusLabel2_Click(object sender, EventArgs e)
        {
        }

        private void button11_Click(object sender, EventArgs e)
        {
            try
            {
                dgv1.AllowUserToAddRows = false; //不显示最后空白行
                string constr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
                MySqlConnection conn = new MySqlConnection(constr);
                String sqlId = "SELECT serviceaddress, systemversion, webversion, webcorepath, webpath, webname, langues, webport, sqltype, sqlpath, sqlport, servicestime, nowhy, stautimes, clostimes, notie, servicename, businessname, servicepurpose, nykeep, protect, customername, uppertimes, datapasswd FROM yishaadmin.sys_user_data;";
                //string sqlId = "SELECT serviceaddress,customername FROM yishaadmin.sys_user_data;";
                conn.Open();
                MessageBox.Show("数据更新成功！");
                MySqlCommand cmd = new MySqlCommand(sqlId, conn);
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds, "sys_user_data");
                if (ds != null && ds.Tables.Count > 0)
                {
                    dgv1.DataSource = ds.Tables[0];
                }
                conn.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //安全建设信息表
            //dataGridView2.AllowUserToAddRows = false;//不显示最后一行
            this.dgv2.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//选中整行
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                dgv2.AllowUserToAddRows = false;
                //安全信息建设表 更新数据
                string constr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
                MySqlConnection conn = new MySqlConnection(constr);
                String sqlId = "SELECT `number-id`, `equipment-name`, `type`, model, `number-serial`, `auto-times`, `admin-address`, username, password, maintenance, notie FROM yishaadmin.sys_security_data_carry; ";
                conn.Open();
                MessageBox.Show("数据更新成功！");
                MySqlCommand cmd = new MySqlCommand(sqlId, conn);
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds, "sys_security_data_carry");
                if (ds != null && ds.Tables.Count > 0)
                {
                    dgv2.DataSource = ds.Tables[0];
                }
                conn.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
        }

        private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //安全服务记录表
            dataGridView3.AllowUserToAddRows = false;//不显示最后一行
            this.dataGridView3.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//选中整行
        }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                dataGridView3.AllowUserToAddRows = false;
                //安全服务记录
                string constr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
                MySqlConnection conn = new MySqlConnection(constr);
                String sqlId = "SELECT projectname, clonsname, clonsphone, servername, serious, `high-risk`, `medium-risk`, `low-risk`, serverphone, serverspro, stautimes, clostimes, fromnote, proposal, subreport, reportname, subreporttimes, subuser, notie, customername FROM yishaadmin.sys_security_service; ";
                conn.Open();
                MessageBox.Show("数据更新成功！");
                MySqlCommand cmd = new MySqlCommand(sqlId, conn);
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds, "sys_security_service");            //dataGridView1.DataSource=ds.Tables["Student"];此处直接用DataTalbe绑定，与下面两行代码的效果是一样的
                dataGridView3.DataSource = ds;//使用Dataset，单必须指定DataMember，因为DataSet是DataTable的集合，而datagridview只能绑定一个datatable
                dataGridView3.DataMember = "sys_security_service";
                if (ds != null && ds.Tables.Count > 0)
                {
                    dgv2.DataSource = ds.Tables[0];
                }
                conn.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
        }

        private void dataGridView4_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            dataGridView4.AllowUserToAddRows = false;//不显示最后一行
            this.dataGridView4.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//选中整行
        }

        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                dataGridView4.AllowUserToAddRows = false;
                //安全服务记录支持表
                string constr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
                MySqlConnection conn = new MySqlConnection(constr);
                String sqlId = "SELECT Implementer, ipaddress, serviceuser, servienotie, stuatimes, clostimes, status, impleaddress, testaddress, testtypes, notie, serviceimple FROM yishaadmin.sys_security_notie; ";
                conn.Open();
                MessageBox.Show("数据更新成功！");
                MySqlCommand cmd = new MySqlCommand(sqlId, conn);
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds, "sys_security_notie");            //dataGridView1.DataSource=ds.Tables["Student"];此处直接用DataTalbe绑定，与下面两行代码的效果是一样的
                dataGridView4.DataSource = ds;//使用Dataset，单必须指定DataMember，因为DataSet是DataTable的集合，而datagridview只能绑定一个datatable
                dataGridView4.DataMember = "sys_security_notie";
                dataGridView4.Columns[0].HeaderText = "实施商";
                dataGridView4.Columns[1].HeaderText = "服务商";
                dataGridView4.Columns[2].HeaderText = "IP/域名";
                dataGridView4.Columns[3].HeaderText = "服务人员";
                dataGridView4.Columns[4].HeaderText = "服务内容";
                dataGridView4.Columns[5].HeaderText = "开始时间";
                dataGridView4.Columns[6].HeaderText = "结束时间";
                dataGridView4.Columns[7].HeaderText = "实施状态";
                dataGridView4.Columns[8].HeaderText = "实施地区";
                dataGridView4.Columns[9].HeaderText = "测试地点";
                dataGridView4.Columns[10].HeaderText = "测试方式";
                dataGridView4.Columns[11].HeaderText = "备注";
                dataGridView4.Columns[0].DataPropertyName = ds.Tables[0].Columns[0].ToString();
                dataGridView4.Columns[1].DataPropertyName = ds.Tables[0].Columns[11].ToString();
                dataGridView4.Columns[2].DataPropertyName = ds.Tables[0].Columns[1].ToString();
                dataGridView4.Columns[3].DataPropertyName = ds.Tables[0].Columns[2].ToString();
                dataGridView4.Columns[4].DataPropertyName = ds.Tables[0].Columns[3].ToString();
                dataGridView4.Columns[5].DataPropertyName = ds.Tables[0].Columns[4].ToString();
                dataGridView4.Columns[6].DataPropertyName = ds.Tables[0].Columns[5].ToString();
                dataGridView4.Columns[7].DataPropertyName = ds.Tables[0].Columns[6].ToString();
                dataGridView4.Columns[8].DataPropertyName = ds.Tables[0].Columns[7].ToString();
                dataGridView4.Columns[9].DataPropertyName = ds.Tables[0].Columns[8].ToString();
                dataGridView4.Columns[10].DataPropertyName = ds.Tables[0].Columns[9].ToString();
                dataGridView4.Columns[11].DataPropertyName = ds.Tables[0].Columns[10].ToString();
                conn.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            //添加安全服务记录支持表
            Form7 f1 = new Form7();
            f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
            f1.ShowDialog();//禁止操作
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //增加建设信息
            Form5 f1 = new Form5();
            f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
            f1.ShowDialog();//禁止操作
        }

        private void button6_Click(object sender, EventArgs e)
        {
            //增加安全服务记录表
            Form6 f1 = new Form6();
            f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
            f1.ShowDialog();//禁止操作
        }

        private void 操作ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void 关于软件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //关于软件
            Form8 f1 = new Form8();
            f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
            f1.ShowDialog();//禁止操作
        }

        private void 使用帮助ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //软件使用帮助
            Form9 f1 = new Form9();
            f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
            f1.ShowDialog();//禁止操作
        }

        private void 检查更新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // 检查更新
            try
            {
                string version = "0.5";
                string version2 = HttpGet("http://192.168.0.111:12345/api/Update/Version");
                if (version.Equals(version2))
                {
                    MessageBox.Show("已是最新版本：" + version);
                }
                else
                {
                    //MessageBox.Show("发现更新文件，是否确认更新？");
                    update f1 = new update();
                    f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
                    f1.ShowDialog();//禁止操作
                    //showStatus.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void test(object sendr, DoWorkEventArgs e)
        {
            BackgroundWorker bw = sendr as BackgroundWorker;
            string downUrl = HttpGet("http://192.168.0.111:12345/api/Update/DownUrl");
            for (int i = 0; i <= 100; i++)
            {
                bw.ReportProgress(i);
                Thread.Sleep(50);//延时作用，如果不延时就会执行很快 进度条一下就刷到100%
                if (bw.CancellationPending)
                {
                    break;//取消时中断任务
                }
            }

        }

        // http 请去方法
        public string HttpGet(string Url)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
                request.Method = "GET";
                request.ContentType = "text/html;charset=UTF-8";

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                Stream myResponseStream = response.GetResponseStream();
                StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
                string retString = myStreamReader.ReadToEnd();
                myStreamReader.Close();
                myResponseStream.Close();
                return retString;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void button9_Click(object sender, EventArgs e)
        {
            try
            {
                dataGridView5.AllowUserToAddRows = false;
                string constr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
                MySqlConnection conn = new MySqlConnection(constr);
                String sqlId = "SELECT uname,nuser,uphone,umail,uaddress,status,addtimes FROM yishaadmin.sys_user_list; ";
                conn.Open();
                MessageBox.Show("数据更新成功！");
                MySqlCommand cmd = new MySqlCommand(sqlId, conn);
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds, "sys_user_list");            //dataGridView1.DataSource=ds.Tables["Student"];此处直接用DataTalbe绑定，与下面两行代码的效果是一样的
                dataGridView5.DataSource = ds;//使用Dataset，单必须指定DataMember，因为DataSet是DataTable的集合，而datagridview只能绑定一个datatable
                dataGridView5.DataMember = "sys_user_list";
                dataGridView5.Columns[0].HeaderText = "客户名称";
                dataGridView5.Columns[1].HeaderText = "客户姓名";
                dataGridView5.Columns[2].HeaderText = "客户电话";
                dataGridView5.Columns[3].HeaderText = "客户邮箱";
                dataGridView5.Columns[4].HeaderText = "客户地址";
                dataGridView5.Columns[5].HeaderText = "客户状态";
                dataGridView5.Columns[6].HeaderText = "客户加入时间";
                //查看、修改
                //dataGridView5.Columns[7].HeaderText = "操作";
                dataGridView5.Columns[0].DataPropertyName = ds.Tables[0].Columns[0].ToString();
                dataGridView5.Columns[1].DataPropertyName = ds.Tables[0].Columns[1].ToString();
                dataGridView5.Columns[2].DataPropertyName = ds.Tables[0].Columns[2].ToString();
                dataGridView5.Columns[3].DataPropertyName = ds.Tables[0].Columns[3].ToString();
                dataGridView5.Columns[4].DataPropertyName = ds.Tables[0].Columns[4].ToString();
                dataGridView5.Columns[5].DataPropertyName = ds.Tables[0].Columns[5].ToString();
                dataGridView5.Columns[6].DataPropertyName = ds.Tables[0].Columns[6].ToString();
                conn.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            Form10 f1 = new Form10();
            f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
            f1.ShowDialog();//禁止操作
        }

        private void dataGridView5_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            dataGridView5.AllowUserToAddRows = false;//不显示最后一行
            this.dataGridView5.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//选中整行
        }

        private void button12_Click(object sender, EventArgs e)
        {
            //客户资产信息表查询
            if(textBox1.Text == string.Empty)
            {
                MessageBox.Show("搜索的内容不能为空");
            }
            string constr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
            try
            {
                MySqlConnection conn = null;
                conn = new MySqlConnection(constr);
                conn.Open();
                //string sql = string.Format("select customername as'客户名称',serviceaddress as'服务器地址',nykeep as'是否备案',webname as'网站名称',protect as'等保评级',stautimes as'开始时间',clostimes as'结束时间',uppertimes as'上线时间' from sys_user_data where 1=1");
                string sql = string.Format("select * from sys_user_data where 1=1");
                //string strsql = "SELECT * FROM sys_user_data WHERE customername LIKE '%" + textBox1.Text.Trim() + "%'";
                //查询
                if (textBox1.Text.Trim().Length != 0)
                {
                    //'%'+@{0}+'%' 无法识别的方法 ('%',?DeptSelectedValue,'%')
                    //字符串拼接 在 and 前需加空格，否则会报错
                    sql += string.Format(" and customername like '%{0}%'", textBox1.Text.Trim());
                }
                MySqlDataAdapter sda = new MySqlDataAdapter(sql, conn);
                DataSet ds = new DataSet();
                sda.Fill(ds);
                if (ds != null && ds.Tables.Count > 0)
                {
                    dgv1.DataSource = ds.Tables[0];
                }

                conn.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //dataGridView1.DataSource = this.comboBox1.SelectedValue.ToString();
        }

        private void toolStripStatusLabel6_Click(object sender, EventArgs e)
        {
        }

        private void dataGridView5_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
        }

        private void toolStripStatusLabel5_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {
        }

        private void button14_Click(object sender, EventArgs e)
        {
            MessageBox.Show("暂未开发！");
        }

        private void button13_Click(object sender, EventArgs e)
        {
            MessageBox.Show("暂未开发！");
        }

        private void 检查更新ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                string version = "0.5";
                string version2 = HttpGet("http://192.168.0.111:12345/api/Update/Version");
                if (version.Equals(version2))
                {
                    MessageBox.Show("已是最新版本：" + version);
                }
                else
                {
                    //MessageBox.Show("发现更新文件，是否确认更新？");
                    update f1 = new update();
                    f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
                    f1.ShowDialog();//禁止操作
                    //showStatus.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            //进行自动排序
            var dgv = (DataGridView)sender;
            if (dgv.RowHeadersVisible) 
            {
                Rectangle rectangle = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, e.RowBounds.Width, e.RowBounds.Height);
                rectangle.Inflate(-3, 0);
                TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, rectangle, e.InheritedRowStyle.ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
            }

        }

        private void dataGridView5_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {

        }

        private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            
        }

        private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {

        }

        private void 查看数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.dgv1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置整行被选中
            DataGridViewRow drv =  this.dgv1.CurrentRow  ;
            if (drv != null)
            {
              DataRow dr=  (drv.DataBoundItem as DataRowView).Row;
                Form11 f1 = new Form11(dr);
                f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
                f1.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选中一行数据");
            }
        }

        private void 删除数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("抱歉！你暂无权限删除此数据！");
            /*this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            if (this.dataGridView1.SelectedRows.Count > 0)
            {
                //将DataGridView的数据放到row中
                DataRow row = (this.dataGridView1.CurrentRow.DataBoundItem as DataRowView).Row;
                

            }
            else
            {
                MessageBox.Show("请选中一行数据");
            }*/
        }


        private void textBox1_Leave(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void button15_Click(object sender, EventArgs e)
        {
            //判断是否选中datagrid中选择框 多选的方式
            //存在一个问题，当未选中的时候，提示数据过多
#pragma warning disable CS0162 // 检测到无法访问的代码
            for (int i = 0; i < dgv1.Rows.Count; i++)
#pragma warning restore CS0162 // 检测到无法访问的代码
            {
                if ((bool)dgv1.Rows[i].Cells[0].EditedFormattedValue == true)
                {
                    //获取选择的数据
                    Form13 f1 = new Form13();
                    f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
                    f1.ShowDialog();
                    return;
                }
                else
                {
                    //如果没有选择数据
                    MessageBox.Show("请选择一条或多条数据");
                    return;
                    //Close();
                }
            }
        }

        private void button19_Click(object sender, EventArgs e)
        {
            //安全建设信息表查询
            if (textBox2.Text == string.Empty) {
                MessageBox.Show("搜索内容不能为空");
                return;
            }
            string constr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
            try
            {
                MySqlConnection conn = null;
                conn = new MySqlConnection(constr);
                conn.Open();
                //string sql = string.Format("select customername as'客户名称',serviceaddress as'服务器地址',nykeep as'是否备案',webname as'网站名称',protect as'等保评级',stautimes as'开始时间',clostimes as'结束时间',uppertimes as'上线时间' from sys_user_data where 1=1");
                string sql = string.Format("select * from sys_security_data_carry where 1=1");
                //string strsql = "SELECT * FROM sys_user_data WHERE customername LIKE '%" + textBox1.Text.Trim() + "%'";
                //查询
                if (textBox2.Text.Trim().Length != 0)
                {
                    //'%'+@{0}+'%' 无法识别的方法 ('%',?DeptSelectedValue,'%')
                    //字符串拼接 在 and 前需加空格，否则会报错
                    sql += string.Format(" and `number-id` like '%{0}%'", textBox2.Text.Trim());
                }
                MySqlDataAdapter sda = new MySqlDataAdapter(sql, conn);
                DataSet ds = new DataSet();
                sda.Fill(ds);
                if (ds != null && ds.Tables.Count > 0)
                {
                    dgv2.DataSource = ds.Tables[0];
                }
                else
                {
                    //dgv2.Rows[e.RowIndex].ErrorText = "数量格式有问题";
                    MessageBox.Show("未查询到相关数据");
                }
                conn.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
        }

        private void 查看数据ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //查看安全建设详细信息
            this.dgv2.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置整行被选中
            DataGridViewRow drv = this.dgv2.CurrentRow;
            if (drv != null)
            {
                DataRow dr = (drv.DataBoundItem as DataRowView).Row;
                //Form14 f1 = new Form14(dr);
                Form14 f1 = new Form14(dr);
                f1.StartPosition = FormStartPosition.CenterScreen;//居中显示
                f1.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选中一行数据");
                return;
            }
        }

        private void button18_Click(object sender, EventArgs e)
        {

        }

        private void button22_Click(object sender, EventArgs e)
        {
            //安全服务搜索
            if (textBox3.Text == string.Empty)
            {
                MessageBox.Show("搜索内容不能为空");
                return;
            }
            string constr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
            try
            {
                MySqlConnection conn = null;
                conn = new MySqlConnection(constr);
                conn.Open();
                //string sql = string.Format("select customername as'客户名称',serviceaddress as'服务器地址',nykeep as'是否备案',webname as'网站名称',protect as'等保评级',stautimes as'开始时间',clostimes as'结束时间',uppertimes as'上线时间' from sys_user_data where 1=1");
                string sql = string.Format("select * from sys_security_service where 1=1");
                //string strsql = "SELECT * FROM sys_user_data WHERE customername LIKE '%" + textBox1.Text.Trim() + "%'";
                //查询
                if (textBox3.Text.Trim().Length != 0)
                {
                    //'%'+@{0}+'%' 无法识别的方法 ('%',?DeptSelectedValue,'%')
                    //字符串拼接 在 and 前需加空格，否则会报错
                    sql += string.Format(" and customername like '%{0}%'", textBox3.Text.Trim());
                }
                MySqlDataAdapter sda = new MySqlDataAdapter(sql, conn);
                DataSet ds = new DataSet();
                sda.Fill(ds);
                if (ds != null && ds.Tables.Count > 0)
                {
                    dataGridView3.DataSource = ds.Tables[0];
                }
                else
                {
                    //dgv2.Rows[e.RowIndex].ErrorText = "数量格式有问题";
                    MessageBox.Show("未查询到相关数据");
                }
                conn.Close();
            }
            catch(Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
        }

        private void button32_Click(object sender, EventArgs e)
        {
            //判断搜索到客户数据
            if (textBox7.Text == string.Empty)
            {
                MessageBox.Show("搜索的内容不能为空");
                return;
            }
            string constr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString;
            MySqlConnection conn = null;
            conn = new MySqlConnection(constr);
            conn.Open();
            //查询多张数据库的表
            string sql = string.Format("select * from sys_user_data sys_user where 1=1");
            //string strsql = "SELECT * FROM sys_user_data WHERE customername LIKE '%" + textBox1.Text.Trim() + "%'";
            //查询
            try
            {
                if (textBox7.Text.Trim().Length != 0)
                {
                    //'%'+@{0}+'%' 无法识别的方法 ('%',?DeptSelectedValue,'%')
                    //字符串拼接 在 and 前需加空格，否则会报错
                    sql += string.Format(" and customername like '%{0}%'", textBox7.Text.Trim());//在多张表中搜索数据时，如果存在字段相同，会发生冲突，在设计字段的都需要考虑到这个问题
                }
                MySqlDataAdapter sda = new MySqlDataAdapter(sql, conn);
                DataSet ds = new DataSet();
                sda.Fill(ds);
                if (ds != null && ds.Tables.Count > 0)
                {
                    dgv1.DataSource = ds.Tables[0];
                    //输出到窗体内的各个datagrdiview中
                    //dgv2.DataSource = ds.Tables[0];
                    //dataGridView3.DataSource = ds.Tables[0];
                }
                if (ds != null && ds.Tables.Count > 0)
                {
                    dgv2.DataSource = ds.Tables[0];
                }
                if (ds != null && ds.Tables.Count > 0)
                {
                    dataGridView3.DataSource = ds.Tables[0];
                }
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误提示：" + "\r\n" + ex);
            }
        }

        private void button16_Click(object sender, EventArgs e)
        {
            //调用系统打印机

            //获取打印机

            //获取内容，赋值给打印机
        }

        private void toolStripStatusLabel3_Click(object sender, EventArgs e)
        {
            //获取系统时间
            toolStripStatusLabel3.Text = System.DateTime.Now.ToString("F");//F 显示完整的日期及时间
        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void button25_Click(object sender, EventArgs e)
        {

        }

        private void button28_Click(object sender, EventArgs e)
        {

        }

        private void 编辑数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 编辑输出ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void dgv1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}